package com.hxz.pojo;

import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

/**
 * @Description
 * @Author 86199
 * @Date 2021/3/25 11:21
 */
public class FactoryPostProcessor  implements BeanFactoryPostProcessor {

    private FactoryPostProcessor(){
        System.out.println("FactoryPostProcessor构造器执行!");
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("******调用了BeanFactoryPostProcessor");
        String[] beanStr = beanFactory
                .getBeanDefinitionNames();
        for (String beanName : beanStr) {
            if ("people".equals(beanName)) {
                BeanDefinition beanDefinition = beanFactory
                        .getBeanDefinition(beanName);
                MutablePropertyValues m = beanDefinition.getPropertyValues();
                if (m.contains("name")) {
                    m.addPropertyValue("name", "赵四111");
                    System.out.println("》》》修改了name属性初始值了");
                }
            }
        }
    }
}
